﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using PlanningGIS.Framework;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
//using ESRI.ArcGIS.TOCControl;

namespace PlanningGIS.TocContextMenu.Button
{
    /// <summary>
    /// 作用：清除选中要素
    /// 作者：
    /// 编写日期：2009-03-25
    /// </summary>
    internal  class ClearSelected:BaseCommand 
    {
        IApplication m_Application = null;
        public ClearSelected()
        {
            base.m_caption = "清除选中要素";
            base.m_toolTip = base.Caption;
        }

        public override void OnCreate(object hook)
        {
            m_Application = hook as IApplication;
        }

        public override void OnClick()
        {
            ILayer pLayer = (m_Application as IFramework).TOCControl.CustomProperty as ILayer;
            IFeatureSelection pFeatSel = pLayer as IFeatureSelection;
            if (pFeatSel != null)
            {
                pFeatSel.Clear();
                (m_Application.Document as IMxDocument).ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, (m_Application.Document as IMxDocument).ActiveView.Extent);
            }            
        }
        public override bool Enabled
        {
            get
            {
                if ((m_Application as IFramework).IsMapCtrlactive && (m_Application as IFramework).TOCControl.CustomProperty is IFeatureLayer)
                {
                    ILayer pLayer = (m_Application as IFramework).TOCControl.CustomProperty as ILayer;
                    IFeatureSelection pFeatSel = pLayer as IFeatureSelection;
                    if (pFeatSel == null) return false;
                    return pFeatSel.SelectionSet.Count > 0;
                }
                return false;
            }
        }
        public override int Bitmap
        {
            get
            {
                string bitmapResourceName = "PlanningGIS.TocContextMenu.Res." + this.GetType().Name + ".ico";
                System.IO.Stream stream = GetType().Assembly.GetManifestResourceStream(bitmapResourceName);
                if (stream == null) return 0;

                return new Bitmap(stream).GetHbitmap().ToInt32();
            }
        }
    }
    
}
